package com.javachmapi.springbootsms.qiniuconfig;

import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 写法一、通过@ConfigurationProperties将文件中的属性映射到类文件
 * @author 宋利军
 */
@Data
@Component
@ConfigurationProperties(prefix = "qiniu")
public class QiniuOneConfig {

    private String accessKey;
    private String secretKey;

    public void sendSmsManager(String templateId,String[] iphones,Map map){
        Auth auth = Auth.create(accessKey,secretKey);
        // 实例化一个SmsManager对象
        SmsManager smsManager = new SmsManager(auth);
        try {
            Response resp = smsManager.sendMessage(templateId,iphones, map);
        } catch (QiniuException e) {
            System.out.println(e);
        }
    }

}
